select top 10 * from tblSurveyFeedback Order By EmailID DESC

UPDATE [dbo].[tblSurveyFeedback]
	SET [Q1Ans] = 0,
		[Q2Ans] = 0,
		[Q3Ans] = 0,
		[Q4Ans] = NULL,
		[UserAgent] = '',
		[IPAddress] = '',
		[SubmitDate] = NULL
WHERE [SVFeedBackID] = 37

select top 10 * from tblEmail Where EmailID = 3167

select * from tblCaseProfileIndex Where CaseProfileIndex = 4280

CaseRefID = 3167 And CaseSourceID = 1

Update tblSurveyFeedback SET IsSent = 1 Where IsSent = 0

SELECT TOP 1 'E' + RIGHT(CAST(DatePart(YY, E.CreatedDate) as varchar), 2) + CAST(DatePart(month, E.CreatedDate) as varchar) + '-' + CAST(CPI.CaseProfileIndex As varchar) + '-' + CAST(CPI.rowGUID as varchar(max)) + '-' + RIGHT('000000'+ CONVERT(VARCHAR,E.EmailID),6)
		From tblCaseProfileIndex CPI
		INNER JOIN tblEmail E ON CPI.CaseRefID = E.EmailID
		Where CPI.CaseSourceID = 2 
		And E.EmailDirection = 1
		And CPI.CaseRefID = 3167

Select CaseProfileIndex, E.EmailCaseRefNo, RowGuid, E.CreatedDate from tblCaseProfileIndex CPI
		INNER JOIN tblEmail E ON CPI.CaseRefID = E.EmailID
		Where CPI.CaseSourceID = 2 And CPI.IsReplyCase = 0 
	And CPI.CaseRefId = 2015
	AA141-001024
select top 10 * from tblEmail 
Where EmailID = 2015
Order By EmailID DESC
select * from tblCaseProfileIndex Where CaseRefID = 1023 And CaseSourceID = 1
Select dbo.funcCaseProfileIndexGetSurveyCaseRefNo(17779, 1)

select top 10 CPI.CreatedDate CaseReceivedDate, CPI.CaseSourceID, CPI.CaseProfileIndex,
CP.Salutation, CP.Name, CP.SurName,
E.EmailTo, E.EmailStatus,
dbo.funcCaseProfileIndexGetSurveyCaseRefNo(CPI.CaseRefID, CPI.CaseSourceID)
from tblSurveyFeedback SF
INNER JOIN tblEmail E ON SF.EmailID = E.EmailID
INNER JOIN tblCaseProfileIndex CPI ON CPI.CaseProfileIndex = SF.CaseProfileIndex
INNER JOIN tblContactProfile CP ON CP.ContactProfileiD = CPI.ContactProfileID
Where CPI.CaseProfileIndex = 21561


select top 10 * from tblCaseProfileIndex Where CaseProfileIndex = 21925

select * from tblEmail Where EmailID = 34302
select * from tblEmailMessage Where EmailID = 34302